﻿using Microsoft.AspNetCore.Mvc;
using ServiceCore.Entity.Core;
using ServiceCore.Entity.Model;
using ServiceCore.Service;
using ServiceCore.WebApi.jwt;

namespace ServiceCore.WebApi.Controllers
{
    /// <summary>
    /// 标签
    /// </summary>
    [Route("Api/[controller]/[action]")]
    [ApiController]
    public class ThresholdController : ApiJwtController
    {
        private ThresholdService thresholdService = new ThresholdService();

        /// <summary>
        /// 列表
        /// </summary>
        /// <arg name="arg"></arg>
        /// <returns></returns>
        [HttpPost]
        public BaseParam<ThresholdInfo, List<ThresholdInfo>> List(BaseParam<ThresholdInfo, List<ThresholdInfo>> arg)
        {
            arg = thresholdService.Threshold_List(arg);

            return arg;
        }

        /// <summary>
        /// 单个
        /// </summary>
        /// <arg name="arg"></arg>
        /// <returns></returns>
        [HttpPost]
        public BaseParam<ThresholdInfo, ThresholdInfo> GetModel(BaseParam<ThresholdInfo, ThresholdInfo> arg)
        {
            arg.Data = thresholdService.GetById(arg.Id);
            //if (arg.Data != null)
            //    arg.Data.ServicesTypeName = GlobalVar.GetEnumVal(arg.Data.ServicesType);

            return arg;
        }

        /// <summary>
        /// 新增
        /// </summary>
        /// <arg name="arg"></arg>
        /// <returns></returns>
        [HttpPost]
        public BaseParam<ThresholdInfo, long> Add(BaseParam<ThresholdInfo, long> arg)
        {
            var userInfo = GetJwtUserInfo();
            arg.Param.CreateUserId = userInfo.Id;
            arg = thresholdService.Threshold_Add(arg);

            return arg;
        }

        /// <summary>
        /// 编辑
        /// </summary>
        /// <arg name="arg"></arg>
        /// <returns></returns>
        [HttpPost]
        public BaseParam<ThresholdInfo, long> Edit(BaseParam<ThresholdInfo, long> arg)
        {
            arg = thresholdService.Threshold_Edit(arg);

            return arg;
        }

        /// <summary>
        /// 删除
        /// </summary>
        /// <arg name="arg"></arg>
        /// <returns></returns>
        [HttpPost]
        public BaseParam<ThresholdInfo, long> Del(BaseParam<ThresholdInfo, long> arg)
        {
            arg = thresholdService.Threshold_Delete(arg);

            return arg;
        }
    }
}
